package com.nchu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.nchu.entity.OrderDetail;
import com.nchu.mapper.OrderDetailMapper;
import com.nchu.service.IOrderDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yaojie
 * @since 2025-01-09
 */
@Service
public class OrderDetailServiceImpl extends ServiceImpl<OrderDetailMapper, OrderDetail> implements IOrderDetailService {
    @Autowired
    private OrderDetailMapper orderDetailMapper;

    // 根据订单 ID 查询订单详情
    public List<OrderDetail> getOrderDetailsByOrderId(Integer orderId) {
        QueryWrapper<OrderDetail> wrapper = new QueryWrapper<>();
        wrapper.eq("order_id", orderId);  // 根据订单 ID 查询对应的订单详情
        return orderDetailMapper.selectList(wrapper);
    }

    @Override
    public boolean removeByOrderIds(List<String> orderIds) {
        // 使用 MyBatis-Plus 的 QueryWrapper 构造删除条件
        return orderDetailMapper.delete(new QueryWrapper<OrderDetail>().in("order_id", orderIds)) > 0;
    }
}
